<?php
namespace app\spadmin\controller;
use app\common\controller\Backend;
use Exception;
use think\Config;
use think\Db;

class Actionlog extends Backend{

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('ActionLog');
    }

    public function index(){

        $this->request->filter(['strip_tags', 'trim']);
        if($this->request->isAjax()){
            $data = $this->request->param();
            if (isset($data['keywords']) && $data['keywords']) {
                $map['username|mobile'] = ['like', '%' . $data['keywords'] . '%'];
            }
            if (isset($data['status']) && $data['status']) {
                $map['status'] = $data['status'];
            } else {
                $map['status'] = 1;
            }
            $list =   $this->model->where($map)->order('create_time desc')->paginate($data['limit'])->toArray();
            foreach ($list['data'] as $key => &$value) {
                if($value['module'] == 'spadmin'){
                    $value['title'] = '后台';
                }else{
                    $value['title'] = '用户';
                }
                if($value['type'] == 1){
                    $value['typename'] = '操作';
                }else{
                    $value['typename'] = '登录';
                }
            }
            return $this->result($list);
        }
        return $this->view->fetch();
    }
}
